﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_WarrantyType
    {
    	#region public properties
		[Required(ErrorMessage="Warranty Type Code Required")]
		public string WarrantyTypeCode { get; set; }
		public string WarrantyTypeName { get; set; }
		public decimal? Period { get; set; }
		public string Unit { get; set; }
		public bool? Disabled { get; set; }
		public string Description { get; set; }
		#endregion

		#region constructor
		public pa_WarrantyType(){ }

		public pa_WarrantyType(IDataReader rd)
		{
			this.WarrantyTypeCode = rd["WarrantyTypeCode"].ToString();
			this.WarrantyTypeName = rd["WarrantyTypeName"].ToString();
			this.Period = rd["Period"].Equals(DBNull.Value) ? (decimal?)null : (decimal)rd["Period"];
			this.Unit = rd["Unit"].ToString();
			this.Disabled = rd["Disabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Disabled"];
			this.Description = rd["Description"].ToString();
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBpa_WarrantyType.Create(WarrantyTypeCode, WarrantyTypeName, Period, Unit, Disabled, Description);
        }

        private bool Update()
        {
            return DBpa_WarrantyType.Update(WarrantyTypeCode, WarrantyTypeName, Period, Unit, Disabled, Description);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(WarrantyTypeCode != string.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(string WarrantyTypeCode)
        {
            return DBpa_WarrantyType.Delete(WarrantyTypeCode);
        }

        public static List<pa_WarrantyType> GetAll()
        {
            return ObjectClass.CreateList<pa_WarrantyType>(DBpa_WarrantyType.GetAll());
        }

        public static pa_WarrantyType GetByKey(string WarrantyTypeCode)
        {
            return ObjectClass.CreateInstance<pa_WarrantyType>(DBpa_WarrantyType.GetByKey(WarrantyTypeCode));
        }

        public static List<pa_WarrantyType> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_WarrantyType>(DBpa_WarrantyType.GetByTop(top, where, order));
        }
		#endregion
	}
}
